import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '@/views/recommend'
// import ranking from '@/views/ranking'
// import singer from '@/views/singer'
import guide from '@/components/public/guide'
Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:"recommend"
  },
  {
    path:'/guide',
    name:'guide',
    component:guide
  },
  {
    path: '/recommend',
    name: 'recommend',
    component: recommend,
    // 路由元信息
    meta:{
      Headers:true,
    },
  },
  {
    path: '/ranking',
    name: 'ranking',
    component:()=>import("../views/ranking.vue"),//懒加载
    meta:{
      Headers:true,
    },
  },
  {
    path: '/singer',
    name: 'singer',
    component:()=>import("../views/singer.vue"),//懒加载
    meta:{
      Headers:true,
    }
  },
  {
    path: '/mv',
    name: 'mv',
    component:()=>import("../views/mv.vue"),//懒加载
    meta:{
      Headers:true,
    }
  },
  {
    path: '/my',
    name: 'my',
    component:()=>import("../views/my.vue"),//懒加载
    meta:{
      Headers:true,
    },
        // 独享路由守卫
    beforeEnter: (to, from, next) => {
      let login = window.localStorage.getItem("login");
      // 判断登录情况
      if(!login){
        next("/login");
        return 
      }else{
        next();
      }
    }
  },
  {
    path: '/login',
    name: 'login',
    component:()=>import("../components/base/login.vue"),//懒加载
    meta:{
      Headers:true,
    }
  },
  {
    path: '/search',
    name: 'search',
    component:()=>import("../components/search/search.vue"),//懒加载
    meta:{
      Headers:true,
    }
  },
  {
    path: '/ranking/rankList',
    name: 'rankList',
    component:()=>import("../components/ranking/rankList.vue"),//懒加载
  },
  {
    path: '/singer/singerList',
    name: 'singerList',
    component:()=>import("../components/singer/singerList.vue"),//懒加载
  },
  {
    path: '/recommend/personalized',
    name: 'personalized',
    component:()=>import("../components/recommend/personalized.vue"),//懒加载
  },
  {
    path: '/recommend/album',
    name: 'album',
    component:()=>import("../components/recommend/album.vue"),//懒加载
  },
  {
    path: '/recommend/album/albumList',
    name: 'albumList',
    component:()=>import("../components/recommend/albumList.vue"),//懒加载
  },
  {
    path: '/mv/mvdetail',
    name: 'mvdetail',
    component:()=>import("../components/mv/mvdetail.vue"),//懒加载
  },
  {
    path: '/my/message',
    name: 'message',
    component:()=>import("../components/my/message.vue"),//懒加载
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to,from,next)=>{
//   let login = window.localStorage.getItem("login");
//   // 登录界面
//   if(to.path == "/login"){
//     next();
//     return;
//   }else{
//     // 判断登录情况
//     if(!login){
//       next("/login");
//       return;
//     }else{
//       next();
//     }
//   }
// })

export default router
